<template>
  <rx-layout>
    <div slot="center" style>
      <rx-fit :isheader="isheader">
        <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
          <div class="table-operator">
            <rx-button
              alias="insRemindDefAdd"
              :butn-icon="'plus'"
              :butn-type="'primary'"
              :show-no-right="true"
              @click="add"
              >{{$ti18('rxList.newBtn','新建')}}
            </rx-button>

          </div>
          <span class="search-btn-box" v-if="!isheader">
            <span class="search-btn" @click.stop="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
          </span>
        </div>
        <div  btnalign="right" slot="searchbar" v-if="fitSearch" @search="search" @cancel="cancel" @close="closeSearchbar">
          <a-form :layout="colLayout">
            <a-row :gutter="24">
              <a-col :span="colSpan">
            <a-form-item :label="i18n('form.subject','主题')">
              <a-input :placeholder="i18n('form.subject','主题','input')" v-model="queryParam.Q_SUBJECT__S_LK" />
            </a-form-item>
              </a-col>
              <a-col :span="colSpan">
            <a-form-item style="width: 100%" :label="i18n('form.available','是否启用')">
              <a-radio-group
                v-model="queryParam.Q_ENABLED__S_EQ"
                v-decorator="['enabled', { rules: [{ required: true, message: i18n('list.type','类型','select') }] }]"
              >
                <a-radio value="YES">{{i18n('form.enable','启用')}}</a-radio>
                <a-radio value="NO">{{i18n('form.disable','禁用')}}</a-radio>
              </a-radio-group>
            </a-form-item>
              </a-col>

              <a-col :span="colSpan">
            <a-form-item style="width: 100%" :label="i18n('form.setType','设置类型')">
              <a-radio-group
                v-model="queryParam.Q_TYPE__S_EQ"
                v-decorator="['queryParam.Q_TYPE__S_LK', { rules: [{ required: true, message: i18n('form.setType','设置类型','select') }] }]"
              >
                <a-radio value="function">{{i18n('form.methodGroovy','调用方法（groovy语法）')}}</a-radio>
                <a-radio value="sql">{{i18n('form.sql','调用sql语句')}}</a-radio>
              </a-radio-group>
            </a-form-item>
              </a-col>
            </a-row>
          </a-form>
        </div>
        <rx-grid
          ref="table"
          :multiSelect="true"
          :columns="columns"
          :bordered="isBorder"
          :defaultPageSize="10"
          url="/api-portal/portal/core/insRemindDef/query"
          :queryParam="queryParam"
          data-field="result.data"
          :pageSizeOptions="['10', '30', '40']"
          rowKey="id"
          @selectChange="onSelectChange"
        >
          <span slot="enabled" slot-scope="{ text, record }">
            <a-tag :color="enabledMap[text].color">
              <span>{{ enabledMap[text].text }}</span>
            </a-tag>
          </span>
          <span slot="action" slot-scope="{ text, record }" class="actionIcons">
            <span v-if="editEnable && showBtn(false)" @click="edit(record)">{{$ti18('rxList.editBtn','编辑')}}</span>
            <span v-if="editEnable && showBtn(false)" @click="editPermission(record.id)" :title="i18n('list.editPermission','权限编辑')">{{i18n('list.editPermission','权限编辑')}}</span>
            <span v-if="removeEnable && showBtn(false)" @click="delByIds([record.id])">{{$ti18('rxList.delBtn','删除')}}</span>
          </span>
        </rx-grid>
      </rx-fit>
    </div>
  </rx-layout>
</template>

<script>
import InsRemindDefApi from '@/api/portal/core/insRemindDef'
import InsRemindDefEdit from './InsRemindDefEdit'
import { BaseList, Api, Util } from "@lowcode/jpaas-common-lib"

import InsPortalPermissionEdit from './InsPortalPermissionEdit.vue'
export default {
  name: 'InsRemindDefList',
  mixins: [BaseList],
  components: {
    InsPortalPermissionEdit,
  },
  data() {
    return {
      columns: [
        {
          title: this.$ti18('rxList.index','序号'),
          type: 'indexColumn',
          width: 40,
          dataIndex: 'serial',
          scopedSlots: { customRender: 'serial' },
        },
        { title: this.i18n('form.subject','主题'), dataIndex: 'subject', width: 120 },
        { title: this.i18n('form.sn','排序'), dataIndex: 'sn', width:40 },
        { title: this.i18n('form.enable','启用'), dataIndex: 'enabled', width: 40, scopedSlots: { customRender: 'enabled' } },
          {title: this.$ti18('rxForm.createTime','创建时间'), dataIndex: 'createTime',  width: 80},
        { title: this.$ti18('rxList.action','操作'), width: 80, dataIndex: 'action', scopedSlots: { customRender: 'action' } },
      ],
      component: InsRemindDefEdit,
      comment: this.i18n('list.comment','消息提醒'),
      widthHeight: ['900px', '700px'],
      enabledMap: {
        YES: { color: 'green', text: this.i18n('form.enable','启用') },
        NO: { color: 'red', text: this.i18n('form.disable','禁用') },
      },
    }
  },
  methods: {
    i18n(name,text,key){
        return this.$ti18(name,text,"InsRemindDef",key);
    },
    editPermission(pkId) {
      Api.setClient('webApp', 'webApp')
      var conf = {
        pkId: pkId,
        component: InsPortalPermissionEdit,
        title: this.i18n('list.editPermissionTitle','权限设计'),
        max: true,
      }
      var self_ = this
      var baseConf = {
        curVm: self_,
        data: {
          menuType: 'remind',
          pkId: conf.pkId,
          callback: function (data) {},
        },
      }
      let config = Object.assign(baseConf, conf)
      Util.open(config, function (action) {})
    },
    delById(ids) {
      return InsRemindDefApi.del({ ids: ids.join(',') })
    },
    getListByParams(parameter) {
      return InsRemindDefApi.query(parameter)
    },
    search() {
      this.$refs.table.loadData()
    },
    cancel() {
      this.resetSearch()
    },
    closeSearchbar(){
      //关闭过滤弹窗；（点击X触发）
      this.fitSearch = false ;
    },
  },
}
</script>
<style scoped>

</style>

